<html xmlns="http://www.w3.org/1999/html">
<head>
    <meta charset="UTF-8">
    <title></title>

    <script src="/forum/public/static/js/jquery1.8.3/jquery.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            setpage();
            var load_user="{$Request.session.user}";
            if (load_user!==""){
                //var content="<font style='color: white'>论坛列表&nbsp;&nbsp;&nbsp;欢迎："+load_user+"，"+"<a href='/forum/index.php/user/logout'>注销</a></font>";
                $("#load_message").html(load_user+"|<a href='/forum/index.php/user/logout'>注销</a>");
            }
            /*
             var m_id=getUrlParam('mid');
             $.post("/forum/index.php/thread/thread/thread_list", {"method": "list_thread", "m_id": m_id}, function (data) {

             if (!data){
             alert(data);
             $("#thread tbody").append("<tr><td colspan='5'>此栏目还未发帖！</td></tr>")
             }

             $("#page_banner").html(data.banner);
             $.each(data.content, function () {
             $("#thread tbody").append("<tr><td></td><td>"+this.title+"</td><td>"+this.name+"</td><td></td><td>"+this.last_time+"</td></tr>");
             });
             }, "json");
             */
        });
        var curpage = '';
        var js_method;
        function setpage(page) {
            var m_id = getUrlParam('mid');
            $.ajax({
                url: "/forum/index.php/thread/thread/thread_list",
                type: 'POST',
                data: {"p": page, "m_id": m_id},
                dataType: "json",
                success: function (data, textStatus, jqXHR) {
                    curpage = page; //将当前页赋值给curpage，以供下面的删除或者修改后，刷新并保留在当前页
                    js_method = "setpage";
                    if (data.total == 0) {
                        $("#head_list").html(data.head_list);
                        $("#thread tbody").append("<tr><td colspan='5'>该版块还未发帖！</td></tr>")
                    } else {
                        $("#page_banner").html(data.banner);
                        $("#head_list").html(data.head_list);
                        $("#thread_list").empty();
                        !page ? page = 1 : page;
                        var num = (page - 1) * 20;
                        $.each(data.content, function () {
                            num += 1;//给每行赋值序号
                            //var list=
                            $("#thread_list").append("<li><div class='ftitle'><a href='/forum/index.php/thread/read.html?mid="+this.m_id+"&id="+this.id+"'>" + this.title + "</a></div><div class='fuser'>"+this.name+" <br>"+this.first_time+"</div> <div class='fre'>208<br>7611 </div><div class='flast'>最后回复<br>"+this.last_time+"</div></li>")
                            //$("#thread tbody").append("<tr><td></td><td><a href='/forum/index.php/thread/read.html?mid="+this.m_id+"&id="+this.id+"'>" + this.title + "</a></td><td>" + this.name + "</td><td></td><td>" + this.last_time + "</td></tr>")
                        });
                    }
                },
                error: function (jqXHR) {
                    alert("页面加载错误！AJAX返回错误" + jqXHR.status);
                }
            });
        }

        //获取url中的参数
        function getUrlParam(name) {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
            var r = window.location.search.substr(1).match(reg);  //匹配目标参数
            if (r != null)
                return unescape(r[2]);
            return null; //返回参数值
        }

        function ft() {
            var m_id = getUrlParam('mid');
            var load_user="{$Request.session.user}";
            if(load_user==""){
                alert("请先登录！")
            }else {
                window.location.href = '/forum/index.php/thread/post.html?mid=' + m_id;
            }
        }

        function insert() {
            window.location.href = '/forum/index.php/thread/insert'
        }

        function search(page) {
            var kw=$("#kw").val();
            var m_id = getUrlParam('mid');
            $.ajax({
                url: "/forum/index.php/thread/Search",
                type: 'POST',
                data: {"p": page, "m_id": m_id,"kw":kw},
                dataType: "json",
                success: function (data, textStatus, jqXHR) {
                    curpage = page; //将当前页赋值给curpage，以供下面的删除或者修改后，刷新并保留在当前页
                    js_method = "search";
                    curpage=page;
                    if (data.total == 0) {
                        $("#head_list").html(data.head_list);
                        $("#thread_list").empty();
                        $("#thread_list").append("<li><div class='ftitle'><font color='red'>暂无数据！</font></div></li>")
                        $("#page_banner").empty();
                    } else {
                        $("#page_banner").html(data.banner);
                        $("#head_list").html(data.head_list);
                        $("#thread_list").empty();
                        !page ? page = 1 : page;
                        var num = (page - 1) * 20;
                        $.each(data.content, function () {
                            num += 1;//给每行赋值序号
                            //var list=
                            $("#thread_list").append("<li><div class='ftitle'><a href='/forum/index.php/thread/read.html?mid="+this.m_id+"&id="+this.id+"' target='_blank'>" + this.title + "</a></div><div class='fuser'>"+this.name+" <br>"+this.first_time+"</div> <div class='fre'>208<br>7611 </div><div class='flast'>最后回复<br>"+this.last_time+"</div></li>")
                            //$("#thread tbody").append("<tr><td></td><td><a href='/forum/index.php/thread/read.html?mid="+this.m_id+"&id="+this.id+"'>" + this.title + "</a></td><td>" + this.name + "</td><td></td><td>" + this.last_time + "</td></tr>")
                        });
                    }
                },
                error: function (jqXHR) {
                    alert("页面加载错误！AJAX返回错误" + jqXHR.status);
                }
            });
        }
    </script>
    <link rel="stylesheet" href="/forum/public/static/css/forum/forum.css">
    <link rel="stylesheet" href="/forum/public/static/css/forum/public.css">
    <link rel="stylesheet" href="/forum/public/static/css/forum/thread.css">
</head>
<body>
<div class="top-bar">
    <div class="main">
        <div class="t_u" id="load_message">
            <a href="/forum/index.php/user/register.html">注册</a>
            |
            <a href="/forum/index.php/user/login.html" id="login">登录</a>
        </div>
    </div>
</div>
<div class="forum_path" id="head_list">
</div>
<div class="forum_path">
    <input type="text" id="kw" style="width: 40%;">
    <input type="image" src="/forum/public/static/pic/search.jpg" onclick="search()">
</div>
<div class="forum_style">
    <li>
        <span style="width: 550px">主题</span>
        <span style="width: 150px">作者</span>
        <span style="width: 80px">回复</span>
        <span style="width: 150px">最后发表</span>
    </li>
</div>
<div class="forum_main">
    <ul class="flist" id="thread_list">
        <!--
        <li>
            <div class="ftitle">
                <a href="thread.html">微空间”（www.idcbt.com）是最长久的免费云主机</a>
            </div>
            <div class="fuser">
                角烛在燃 <br>2017-05-03 14:55:24
            </div>
            <div class="fre">
                208<br>7611
            </div>
            <div class="flast">
                苍穹一怒
                <br>
                2013-5-27 00:13
            </div>
        </li>
        -->
    </ul>
    <!--
<table width="60%" border="1" align="center" cellspacing="0" id="thread">
 <thead>
 <tr>
     <td colspan="5" style="background: #F2F2F2" id="head_list">

     </td>
 </tr>
 <tr>
     <td colspan="4" style="background: #B10707"><font color="white">帖子列表</font></td>
     <td style="background: #B10707" align="center">
         <button onclick="ft()">发帖</button>
         <button onclick="insert()">插入数据</button>
     </td>

 </tr>
 <tr>
     <td width="10%" style="background: #FDF7AF" align="center">状态</td>
     <td width="50%" style="background: #FDF7AF" align="center"> 主题列表</td>
     <td width="10%" style="background: #FDF7AF" align="center">作者</td>
     <td width="10%" style="background: #FDF7AF" align="center">回复</td>
     <td width="20%" style="background: #FDF7AF" align="center">最后更新</td>
 </tr>
 </thead>
 <tbody>
 </tbody>
</table>

<div id="page_banner" align="center"></div>
-->

</div>
<div class="forum_top">
    <input id="reply" type="image" src="/forum/public/static/pic/post.png" onclick="ft()">
    <div class="page_num">
        <li id="page_banner"></li>
    </div>
</div>
</body>
</html>

